//https://leetcode.cn/problems/palindrome-partitioning/?envType=study-plan-v2&envId=top-100-liked

#include <string>
#include <vector>
#include <set>

using namespace std;

class Solution {
public:
    bool judge(string s, int left, int right)
    {
        while(left<right)
        {
            if(s[left]!=s[right])
            {
                return false;
            }
            left++;
            right--;
        }
        return true;
    }
    
    void DFS(string s, int start, vector<string>& tmp, vector<vector<string>>& res)
    {
        if(start==s.length())
        {
            res.push_back(tmp);
            return;
        }
        for(int i=start;i<s.length();i++)
        {
            if(judge(s,start,i))
            {
                tmp.push_back(s.substr(start,i-start+1));
                DFS(s,i+1,tmp,res);
                tmp.pop_back();
            }
        }
        
    }
    
    vector<vector<string>> partition(string s) 
    {
        int n=s.length();
        vector<vector<string>> res;
        vector<string> tmp;
        DFS(s,0,tmp,res);
        return res;        
    }
};